/**
 * @param {number[]} nums
 * @return {number}
 */
var minMaxGame = function(nums) {
  if(nums.length == 1)
    return nums[0];
  newNums = [...nums];
  while(newNums.length > 1) {
    let tempNums = [];
    for(let i = 0; i < newNums.length / 2; i++) {
      if(i % 2 == 0) {
        tempNums[i] = Math.min(newNums[2 * i], newNums[2 * i + 1]);
      } else {
        tempNums[i] = Math.max(newNums[2 * i], newNums[2 * i + 1]);
      }
    }
    newNums = [...tempNums];
  }
  return newNums[0];
};
let nums = [1,3,5,2,4,8,2,2];
console.log(minMaxGame(nums));
nums = [3];
console.log(minMaxGame(nums));
